package com.chaochis.wind.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaochis.wind.enums.AccountType;
import com.chaochis.wind.enums.UserType;
import com.chaochis.wind.user.mapper.WindAccountMapper;
import com.chaochis.wind.user.service.WxAccountService;
import com.chaochis.wind.user.vo.WindAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * 微信账户管理的service
 * @author 刘超/chaochis
 */
@Service("wxAccountService")
public class WxAccountServiceImpl extends WindAccountServiceImpl implements WxAccountService {
  @Autowired
  @Qualifier("windAccountMapper")
  private WindAccountMapper wxAccountMapper;

  /**
   * 通过openId获取单个微信账户
   * @param openId 微信的openId
   * @return 获取单个微信账户
   */
  @Override
  public WindAccount getWxAccountByOpenId(String openId) {
    QueryWrapper<WindAccount> queryWrap = new QueryWrapper<>();
    queryWrap.eq("account_name", openId);
    queryWrap.eq("account_type", AccountType.WxAccount);
    queryWrap.eq("user_type", UserType.WxUser);
    return this.wxAccountMapper.selectOne(queryWrap);
  }

}
